<?php
namespace app\index\controller;
use think\Controller;
use app\index\controller\Base;
use think\Request;
use think\Db;
use app\index\model\blog;
class Search extends Base
{
    public function index()
    {
    	$base = new Base();
    	$base->bloginfo();
    	if (input('key') != "") {
    		$data = [
    			'__token__'=> input('__token__')
    		];
    		$validate = new \app\index\validate\search;
    		if (!$validate->check($data)) {
    			echo '请不要重复提交';
    		}else{
    			$key = input('key');
                $artice = blog::
                where('type', '=', 'artice')
                ->where('show', '=', '1')
                ->where('title','like','%'.$key.'%')
                ->where('content','like','%'.$key.'%')
                ->order('time','desc')
                ->paginate(5);
                // 获取分页显示
                $page = $artice->render();
                $this->assign('page', $page);
    			return $this->fetch('./index/search',['artice'=>$artice]);
    		}
    	}else{
    		$artice = blog::
                where('type', '=', 'artice')
                ->where('show', '=', '1')
                ->order('time','desc')
                ->paginate(5);
                // 获取分页显示
                $page = $artice->render();
                $this->assign('page', $page);
    		    return $this->fetch('./index/search',['artice'=>$artice]);
    	}
       
    }
}
